package com.swak.im.worker;

import com.swak.annotation.ImOps;
import com.swak.im.Im;
import com.swak.im.ImConfig;
import com.swak.im.mapping.MappingService;
import com.swak.im.queue.QueueService;
import com.swak.im.storage.StorageService;
import com.swak.metrics.MetricsFactory;
import com.swak.registry.RegistryService;
import com.swak.security.Subject;
import com.swak.vertx.protocol.im.ImContext;

/**
 * 分布式ImWorker 处理器;
 * 
 * @author 618lf
 */
public class DistributedImWorker extends AbstractImWorker {

	public DistributedImWorker(ImConfig config, Im im, StorageService storageService, RegistryService registryService,
			MappingService mappingService, QueueService queueService, MetricsFactory metricsFactory) {
		super(config, im, storageService, registryService, mappingService, queueService, metricsFactory);
	}

	/**** 分布式处理 ****/

	@Override
	public void handle(ImContext context, Subject subject) {
		if (context.getOps() == ImOps.Connect) {
			this.handleConnect(context, subject);
		} else if (context.getOps() == ImOps.Close) {
			this.handleClose(context, subject);
		} else if (context.getOps() == ImOps.Message) {
			this.handleMessage(context, subject);
		}
	}

	/**
	 * 连接处理：
	 * 
	 * @param context
	 * @param subject
	 */
	protected void handleConnect(ImContext context, Subject subject) {

	}

	/**
	 * 关闭连接处理：
	 * 
	 * @param context
	 * @param subject
	 */
	protected void handleClose(ImContext context, Subject subject) {

	}

	/**
	 * 消息处理：
	 * 
	 * 1. 消息存储
	 * 2. 消息转发
	 * 
	 * @param context
	 * @param subject
	 */
	protected void handleMessage(ImContext context, Subject subject) {

	}
}
